import testApi from '@/api/testApi'

export default {
  name: 'supplierManagement',
  data() {
    return {
      supplierList: [],
      supplierSelected: '',
      supplierInfoShow: { },
      transactionInfoList: []
    }
  },
  created() {
  },

  async mounted() {
    await this.getTransactionInfoList()
    await this.getSupplierList()
  },
  methods: {
    async getTransactionInfoList() {
      await testApi.getTransactionInfoList().then((res) => {
        this.transactionInfoList = res.data
      }).catch((error) => {
        this.transactionInfoList = [
          { id: '0', userId: '10000', supplierId: '0', transInfo: '计算服务', transDate: '2023-07-02', state: '0' },
          { id: '1', userId: '20000', supplierId: '1', transInfo: '存储服务', transDate: '2023-07-02', state: '1' },
          { id: '2', userId: '30000', supplierId: '2', transInfo: '计算服务', transDate: '2023-07-02', state: '2' },
          { id: '3', userId: '40000', supplierId: '3', transInfo: '存储服务', transDate: '2023-07-02', state: '2' },
          { id: '4', userId: '50000', supplierId: '1', transInfo: '计算服务', transDate: '2023-07-02', state: '0' },
          { id: '5', userId: '60000', supplierId: '1', transInfo: '存储服务', transDate: '2023-07-02', state: '1' },
          { id: '6', userId: '80000', supplierId: '1', transInfo: '存储服务', transDate: '2023-07-02', state: '2' },
          { id: '7', userId: '10000', supplierId: '1', transInfo: '计算服务', transDate: '2023-07-02', state: '1' }
        ]
      })
    },
    async getSupplierList() {
      await testApi.getSupplierList().then((res) => {
        this.supplierList = res.data
        this.initData()
      }).catch((error) => {
        this.supplierList = [
          { id: 0, name: '阿里云', hostNum: 100, normalHostNum: 95, abnormalHostNum: 5, computeCredenceValue: 90, memoryCredenceValue: 80, transactionCredenceValue: 90, compreCredenceValue: 85 },
          { id: 1, name: '联通云', hostNum: 100, normalHostNum: 98, abnormalHostNum: 2, computeCredenceValue: 95, memoryCredenceValue: 85, transactionCredenceValue: 95, compreCredenceValue: 90 },
          { id: 2, name: '华为云', hostNum: 100, normalHostNum: 89, abnormalHostNum: 11, computeCredenceValue: 90, memoryCredenceValue: 90, transactionCredenceValue: 90, compreCredenceValue: 90 },
          { id: 3, name: '火山云', hostNum: 100, normalHostNum: 93, abnormalHostNum: 7, computeCredenceValue: 85, memoryCredenceValue: 85, transactionCredenceValue: 90, compreCredenceValue: 85 }
        ]
        this.initData()
      })
    },
    async changeSupplier() {
      await testApi.getSupplierInfoById({ id: this.supplierSelected }).then((res) => {
        this.supplierInfoShow = res.data
      }).catch((error) => {
        for (let i = 0; i < this.supplierList.length; i++) {
          if (this.supplierList[i].id === this.supplierSelected) {
            this.supplierInfoShow = this.supplierList[i]
          }
        }
      })
    },
    initData() {
      if (this.supplierList.length > 0) {
        this.supplierSelected = this.supplierList[0].id
        this.supplierInfoShow = this.supplierList[0]
      }
    },
    fullScreen() {
      const element = document.getElementById('entirety')
      if (element.requestFullscreen) {
        element.requestFullscreen()
      } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen()
      } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen()
      } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen()
      }
    },
    getStateText(state) {
      switch (state) {
        case '0':
          return {
            label: '已完成',
            type: ''
          }
        case '1':
          return {
            label: '未完成',
            type: 'warning'
          }
        case '2':
          return {
            label: '进行中',
            type: 'success'
          }
      }
    }

  }
}
